{extend name="index/iframe" /}

{block name="content"}
<div style="padding: 10px;">
    <form class="layui-form" action="" id="searchBox">
        <div class="layui-inline">
            <div class="layui-input-inline">
                {MyTag:channel type='manage' /}
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                {MyTag:game type='manage' /}
            </div>
        </div>
        <div class="layui-inline">
            <input type="text" name="pay_rate" id="pay_rate" class="layui-input" placeholder="分成比例">
        </div>
        <div class="layui-inline">
            <input type="text" name="channel_rate" id="channel_rate" class="layui-input" placeholder="渠道费率">
        </div>
        <div class="layui-inline">
            <input type="text" name="tax_rate" id="tax_rate" class="layui-input" placeholder="税率">
        </div>
        <div class="layui-inline">
            <button class="layui-btn my-btn" lay-submit="" lay-filter="submitBtn">提交</button>
        </div>
    </form>

    <table id="tableBox" lay-filter="tableBox"></table>

    <script type="text/html" id="tableBar">
        <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</button>
    </script>
</div>
{/block}

{block name="css"}{/block}

{block name="js"}
<script>
    layui.use(['form', 'table'], function(){
        var $ = layui.$
            ,table = layui.table
            ,load = layer.load()
            ,form = layui.form;

        //表格初始化
        table.render({
            elem: '#tableBox'
            ,url: '{:url("AuditSdkInfo/custom")}'
            ,page: true
            ,limit: 20
            ,limits: [20,40,60]
            ,loading: true
            ,id: 'tableId'
            ,done: function (res, curr, count) {
                layer.close(load);
            }
            ,cols: [[
                {field:'channel_id', title: '渠道名称'}
                ,{field:'game_id', title: '游戏名称'}
                ,{field:'channel_rate', title: '通道费率'}
                ,{field:'tax_rate', title: '税率'}
                ,{field:'pay_rate', title: '结算比例'}
                ,{title: '操作', align:'center', toolbar:'#tableBar'}
            ]]
        });

        form.on('submit(submitBtn)', function(data){
            var load = layer.load();
            $.post('{:url("AuditSdkInfo/add")}',data.field, function(json){
                layer.close(load);
                if(json.code==0){
                    layer.msg(json.msg, {icon: 1, time: 1000})
                    setTimeout(function(){
                        window.location.reload();
                    }, 1000);
                }else{
                    layer.msg(json.msg, {icon: 0, time: 1000});
                }
            }, 'JSON').error(function(){
                layer.close(load);
                layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
            });
            return false;
        });

        table.on('tool(tableBox)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定要删除吗？', {offset: '250px'}, function(index){
                    var load = layer.load();
                    $.post('{:url("AuditSdkInfo/del")}',{id: data.id}, function(json){
                        layer.close(load);
                        if(json.code==0){
                            obj.del();
                            layer.msg(json.msg, {icon: 1, time:1000})
                        }else{
                            layer.msg(json.msg, {icon: 0, time:1000});
                        }
                    }, 'JSON').error(function(){
                        layer.close(load);
                        layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
                    });
                });
            }
        });

    });
</script>
{/block}